﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using ShredTheLog.Api.DataContracts;
using ShredTheLog.Api;

namespace ShredTheLog.Model
{
    [XmlRoot("VoiceChatUserList")]
    public sealed class VoiceChatUserList
    {
        private static readonly LobbyMembers EmptyLobbyMembers = new LobbyMembers();
        private LobbyMembers _lobbyMembers = EmptyLobbyMembers;
        [XmlElement("LobbyMembers")]
        public LobbyMembers LobbyMembers { get { return _lobbyMembers; } set { _lobbyMembers = value ?? EmptyLobbyMembers; } }

        [XmlElement("ND")]
        public object NotDefined { get; set; }
    }

    public sealed class LobbyMembers
    {
        private static readonly BasicUserInfo[] EmptyUsers = new BasicUserInfo[0];
        private BasicUserInfo[] _users = EmptyUsers;
        [XmlElement("Member")]
        public BasicUserInfo[] Users { get { return _users; } set { _users = value ?? EmptyUsers; } }
    }

    [XmlRoot("TextChatUserList")]
    public sealed class TextChatUserList
    {
        private static readonly ShortUserInfo[] EmptyUsers = new ShortUserInfo[0];
        private ShortUserInfo[] _users = EmptyUsers;
        [XmlElement("U")]
        public ShortUserInfo[] Users { get { return _users; } set { _users = value ?? EmptyUsers; } }
    }

    [XmlRoot("Last15UserList")]
    public sealed class Last15UserList
    {
        private static readonly Last15UserInfo[] EmptyUsers = new Last15UserInfo[0];
        private Last15UserInfo[] _users = EmptyUsers;
        [XmlElement("row")]
        public Last15UserInfo[] Users { get { return _users; } set { _users = value ?? EmptyUsers; } }
    }

    [XmlRoot("ContactList")]
    public sealed class ContactList
    {
        private static readonly Contact[] EmptyUsers = new Contact[0];
        private Contact[] _users = EmptyUsers;
        [XmlElement("row")]
        public Contact[] Users { get { return _users; } set { _users = value != null ? value : EmptyUsers; } }

        /// <summary>
        /// Дополнительная информация об ответе сервера
        /// </summary>
        /// <remarks>
        /// Используется исключительно для отладочных целей.
        /// </remarks>
        [XmlElement("R")]
        public ResponseDetails Response { get; set; }

        [XmlElement("InvalidSSID")]
        public object InvalidSSID { get; set; }

        public sealed class ResponseDetails
        {
            [XmlAttribute("V")]
            public string V { get; set; }
            [XmlIgnore]
            public bool IsEmpty { get { return V == "Empty"; } }
            public override string ToString()
            {
                return V ?? base.ToString();
            }
        }
    }
}
